local jvxiang = fk.CreateSkill {
  name = "jvxiang",
}

jvxiang:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to and move.to == player and move.toArea == Player.Hand and player.phase ~= Player.Draw then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#jvxiang-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    local suits = {}
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Player.Hand and player.phase ~= Player.Draw then
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(cards, info.cardId)
          local suit = Fk:getCardById(info.cardId).suit
          if suit ~= Card.NoSuit then
            table.insertIfNeed(suits, suit)
          end
        end
      end
    end
    room:throwCard(cards, self.name, player, player)
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    if turn_event and not turn_event.data.who.dead then
      room:addPlayerMark(turn_event.data.who, MarkEnum.SlashResidue.."-turn", #suits)
    end
  end,
})

return jvxiang